home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / DVIM72-Mac 1.9.6 / source / dviinit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-14  |  6.6 KB  |  226 lines  |  [TEXT/R*ch]

  1. /**********************************************************************/
  2. /**************************** dviinit.h ********************************/
  3. /**********************************************************************/
  4. /* -*-C-*- dviinit.h */
  5. /*-->dviinit*/
  6. /**********************************************************************/
  7. /****************************** dviinit *******************************/
  8. /**********************************************************************/
  9. #include "dvihead.h"
  10. #include "commands.h"
  11. #include "gendefs.h"
  12. #include "gblprocs.h"
  13. #include "egblvars.h"
  14. #include "m72.h"
  15. #include "mac-specific.h"
  16.  
  17.  
  18. void
  19. dviinit(filestr)        /* initialize DVI file processing */
  20. char *filestr;            /* command line filename string  */
  21. {
  22.     int i;            /* temporary */
  23.     INT16 k;            /* index in curpath[] and curname[] */
  24.     char* tcp;            /* temporary string pointers */
  25.     char* tcp1;            /* temporary string pointers */
  26.  
  27. #if    OS_UNIX
  28. /***********************************************************************
  29. Unix allows binary I/O on stdin and stdout; most other operating systems
  30. do not.  In order  to support this,  we use the  convention that a  null
  31. filestr (NOT  a (char*)NULL)  means the  dvifile is  on stdin,  and  the
  32. translated output is on stdout.  Error logging will be to dvixxx.err  or
  33. dvixxx.dvi-err.  Because random access is required of the dvifile, stdin
  34. may NOT be a pipe; it must be a disk file.
  35. ***********************************************************************/
  36. #define NO_FILENAME (filestr[0] == '\0')
  37. #endif
  38.  
  39.  
  40.     basemag = g_dpi * 5;
  41.     runmag = basemag;
  42.  
  43.     for (k = 0; k < 10; ++k)
  44.     tex_counter[k] = (INT32)0L;
  45.  
  46.     fontptr = (struct font_entry *)NULL;
  47.     hfontptr = (struct font_entry *)NULL;
  48.     pfontptr = (struct font_entry *)NULL;
  49.     fontfp = (FILE *)NULL;
  50.     cache_size = 0;
  51.     nopen = 0;
  52.  
  53.  
  54.     /***********************************************************
  55.     Set up file names and open dvi and plot files.  Simple
  56.     filename parsing assumes forms like:
  57.  
  58.     Unix:    name
  59.         name.ext
  60.         /dir/subdir/.../subdir/name
  61.         /dir/subdir/.../subdir/name.ext
  62.     TOPS-20:    any Unix style (supported by PCC-20)
  63.         <directory>name
  64.         <directory>name.ext
  65.         <directory>name.ext.gen
  66.         device:<directory>name
  67.         device:<directory>name.ext
  68.         device:<directory>name.ext.gen
  69.         [directory]name
  70.         [directory]name.ext
  71.         [directory]name.ext.gen
  72.         device:[directory]name
  73.         device:[directory]name.ext
  74.         device:[directory]name.ext.gen
  75.         logname:name
  76.         logname:name.ext
  77.         logname:name.ext.gen
  78.  
  79.     The Unix style should work  under IBM PC DOS (backslash  can
  80.     usually be  replaced for  forward  slash), and  the  TOPS-20
  81.     style contains VAX VMS as  a subset.  Fancier TOPS-20  names
  82.     are possible (control-V quoting of arbitrary characters, and
  83.     attributes), but they are rare enough that we do not support
  84.     them.  For  TOPS-20  and  VAX VMS,  generation  numbers  are
  85.     recognized as a digit following  the last dot, and they  are
  86.     preserved for the DVI file only.  For the output files,  the
  87.     highest generation  will always  be  assumed.  This  is  for
  88.     convenience with the  TOPS-20 TeX  implementation, which  on
  89.     completion types  in a  command "TeXspool:  foo.dvi.13"  and
  90.     waits for the user to type a carriage return.
  91.  
  92.     We only  need  to  extract the  directory  path,  name,  and
  93.     extension, so the parsing is simple-minded.
  94.  
  95.     ***********************************************************/
  96.  
  97.     tcp = strrchr(filestr,'/'); /* find end of Unix file path */
  98.  
  99. #if    (OS_ATARI | OS_PCDOS)
  100.     if (tcp == (char*)NULL)    /* no Unix-style file path */
  101.     tcp = strrchr(filestr, '\\');    /* try \dos\path\ */
  102. #endif
  103.  
  104. #if OS_THINKC
  105.     if (tcp == (char *)NULL)
  106.         tcp = strrchr(filestr, ':');
  107. #endif
  108.  
  109.  
  110.     if (tcp == (char*)NULL)    /* no file path */
  111.     {
  112.         curpath[0] = '\0';    /* empty path */
  113.         tcp = filestr;    /* point to start of name */
  114.     }
  115.     else            /* save path for later use */
  116.     {
  117.         k = (INT16)(tcp-filestr+1);
  118.         (void)strncpy(curpath, filestr, (size_t)k);
  119.         curpath[k] = '\0';
  120.         tcp++;            /* point to start of name */
  121.     }
  122.  
  123.     tcp1 = strrchr(tcp, '.');    /* find last dot in filename */
  124.  
  125.  
  126. #if    (OS_TOPS20 | OS_VAXVMS)
  127.     if ((tcp1 != (char*)NULL) && isdigit(*(tcp1+1)))
  128.     {                /* then assume generation number */
  129.     tcp2 = tcp1;        /* remember dot position */
  130.     *tcp1 = '\0';        /* discard generation number */
  131.     tcp1 = strrchr(tcp,'.');/* find last dot in filename */
  132.     *tcp2 = '.';        /* restore dot */
  133.     }
  134. #endif
  135.  
  136.     if (tcp1 == (char*)NULL)
  137.     {                /* no dot, so name has no extension */
  138.         (void)strcpy(curname, tcp);    /* save name */
  139.         tcp1 = strchr(tcp, '\0');    /* set empty extension */
  140.     }
  141.     else            /* save name part */
  142.     {
  143.         k = (INT16)(tcp1-tcp);
  144.         (void)strncpy(curname, tcp, (size_t)k);
  145.         curname[k] = '\0';
  146.     }
  147.  
  148.     (void)strcpy(curext, tcp1);    /* save extension */
  149.  
  150.  
  151.     /* DVI file must always have extension DVIEXT; supply one if
  152.     necessary (e.g /u/jones/foo.dvi) */
  153.  
  154.     (void)strcpy(dviname, curpath);
  155.     (void)strcat(dviname, curname);
  156.     if (curext[0] == '\0')
  157.     (void)strcat(dviname, DVIEXT);
  158.     else
  159.     (void)strcat(dviname, curext);
  160.  
  161.  
  162.     /* Font substitution file is PATH NAME SUBEXT (e.g.
  163.        /u/jones/foo.sub).  We do not tell user (via stderr)
  164.        about it until it is needed. */
  165.  
  166.     if (subfile[0] == '\0')    /* no -fsubfile; make default */
  167.     {
  168.     (void)strcpy(subfile, curpath);
  169.     (void)strcat(subfile, curname);
  170.     (void)strcat(subfile, subext);
  171.     }
  172.  
  173.  
  174.  
  175.     dvifp = FOPEN(dviname,RB_OPEN);
  176.     DEBUG_OPEN(dvifp,dviname,RB_OPEN);
  177.  
  178.     if (dvifp == (FILE*)NULL)
  179.     {
  180.         (void)sprintf(message,"dviinit(): %s: can't open [%s]",
  181.         g_progname, dviname);
  182.         Kill_dvi(message);
  183.         return;
  184.     }
  185.  
  186.     /* We try both
  187.     PATH NAME . DVIPREFIX OUTFILE_EXT and
  188.          NAME . DVIPREFIX OUTFILE_EXT,
  189.         in case the user does not have write access to the directory PATH */
  190.  
  191.     if (!quiet)
  192.     {
  193.         (void)printf("[Input from DVI file %s]",dviname);
  194.         printf("\n");
  195.     }
  196.  
  197.     lmargin = (COORDINATE)(leftmargin*((float)XDPI));
  198.     tmargin = (COORDINATE)(topmargin*((float)YDPI));
  199.  
  200. #if JDEB
  201.     printf("[dviinit calling nosignex(dvi,1)]");
  202. #endif
  203.     if ((BYTE)nosignex(dvifp,(BYTE)1) != PRE)
  204.     {
  205.         Kill_dvi( "dviinit(): PRE doesn't occur first--are you sure"
  206.             " this is a DVI file?" );
  207.         return;
  208.     }
  209.  
  210. #if JDEB
  211.     printf("[dviinit calling signex(dvi,1)]");
  212. #endif
  213.     i = (int)signex(dvifp,(BYTE)1);
  214.     if (i != DVIFORMAT)
  215.     {
  216.         (void)sprintf(message,
  217.         "dviinit(): DVI format = %d, can only process DVI format %d files.",
  218.         i, (int)DVIFORMAT);
  219.         Kill_dvi(message);
  220.     }
  221. }
  222.  
  223. /**********************************************************************/
  224. /**********************************************************************/
  225. /**********************************************************************/
  226.